#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=200000;

int max(int a, int b) {
  return a>b ? a : b;
}

int main() {
  freopen("glo.in", "r", stdin);
  freopen("glo.out", "w", stdout);

  static int a[maxn+1];
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }

  static int que[maxn+1], f[maxn+1];
  que[0] = 0;
  for (int i=n; i>0; i--) {
    if (!que[0] || a[i]<que[que[0]]) {
      que[++que[0]] = a[i];
      f[i] = que[0];
    } else {
      int pos=1;
      for (int l=1, r=que[0], mid; l<=r; ) {
	mid = (l+r)/2;
	if (que[mid]>a[i]) {
	  pos = mid+1;
	  l = mid+1;
	} else {
	  r = mid-1;
	}
      }
      que[pos] = a[i];
      f[i] = pos;
    }
  }

  int ans=que[0];
  que[0] = 0;
  for (int i=1; i<n; i++) {
    if (!que[0] || a[i]>que[que[0]]) {
      que[++que[0]] = a[i];
    } else {
      int pos=1;
      for (int l=1, r=que[0], mid; l<=r; ) {
	mid = (l+r)/2;
	if (que[mid]<a[i]) {
	  pos = mid+1;
	  l = mid+1;
	} else {
	  r = mid-1;
	}
      }
      que[pos] = a[i];
    }

    int pos=0;
    for (int l=1, r=que[0], mid; l<=r; ) {
      mid = (l+r)/2;
      if (que[mid]<a[i+1]+x) {
	pos = mid;
	l = mid+1;
      } else {
	r = mid-1;
      }
    }
    ans = max(ans, pos+f[i+1]);
  }

  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
